package com.scfire.project

import java.util.Date
import java.util.SortedSet;

import org.grails.databinding.BindingFormat

import com.scfire.security.Member

/**
 * Copyright 2015 Shudao Info Tech Co. Ltd.  All rights reserved.
 * @author lhzeng
 * @email zenglh@haoshudao.com
 * @date 2015年10月28日 下午2:23:12
 * @version V1.0
 */

class SubProject implements Comparable{
	
	//一起捐描述
	String subdescription

	//筹款目标金额   -1表示不限制
	float subamount
	//筹款剩余金额 
	float subrest
	//已筹款金额
	float subdonate = 0
	//项目配捐金额(因数据库精度问题，选用int)
	int subfdonate = 0
	//筹款进度
	float subprogress = 0
	
	//一起捐参与人数
	int subdonateSize =0
	
	//项目创建时间
	@BindingFormat('yyyy-MM-dd HH:mm')
	Date createDate
	//项目更新时间
	@BindingFormat('yyyy-MM-dd HH:mm')
	Date updateDate
	
	//一起捐赠信息列表
	SortedSet donates
	
	int member
	
	int project
	
	//一起捐发起人,一起捐归属项目
	//static belongsTo = [member:Member,project:Project]	
	//一起捐列表
	//static hasMany = [donates:Donate]

    static constraints = {
		subdescription nullable:true
		subamount nullable:true
		subrest nullable:true
		createDate nullable:true
		updateDate nullable:true
		
		donates nullable:true
		
		subprogress nullable:true
		
		member nullable:true
		project nullable:true
		subdonate nullable:true
    }
	
	public int compareTo(Object o) {
		try{
			-subdonate.compareTo(o?.subdonate)
		}catch(Exception e){
			return 1
		}
	}
}
